#include "proclist.h"

void push(p_list *list, proc710 data)
{
	proc *newElement;
	newElement = (proc*) malloc(sizeof(proc));
	
	newElement->process = data;
	newElement->next = NULL;
	newElement->prev = NULL;
	
	if (list->size == 0)
	{
		list->first = list->last = newElement;
	}
	else
	{
		list->last->next = newElement;
		newElement->prev = list->last;
		list->last = newElement;
	}
	list->size++;
}

proc710 pop(p_list *list)
{
	proc *element = list->first;
	list->first = element->next;
	list->size--;
	
	proc710 p = element->process;
	free(element);
	
	return p;
}

/*void removeElem(p_list *list, pid_t p)
{
	int found = 0;
	proc* toDelete;
	
	// Delete the last element of the list
	proc *current = list->last;
	if (current->process.pid == p)
	{
		toDelete = current;
		current->prev->next = current->next;
		list->size--;
		
		free(toDelete);
		return;
	}
	
	// Delete the first element of the list
	current = list->first;
	if (current->process.pid == p)
	{
		toDelete = current;
		current->next->prev = current->prev;
		list->size--;
		
		free(toDelete);
		return;
	}
	else
		current = current->next; // Gain one position
	
	while (current != NULL && !found)
	{
		if (current->process.pid == p)
		{
			toDelete = current;
			current->prev->next = current->next;
			current->next->prev = current->prev;
			found = 1;
			list->size--;
			
			free(toDelete);
		}
		else
			current = current->next;
	}
}*/
